import { request } from '@/service/request';
import type { RoleSearchParams, RoleVO, System } from '@/service/types/system';

export function getPageList(params?: RoleSearchParams) {
  return request<System.RoleVo>({
    url: '/system/role/list',
    method: 'get',
    params
  });
}

export function getRole(id: number) {
  return request<RoleVO>({
    url: `/system/role/${id}`,
    method: 'GET'
  });
}

export function addRole(data: RoleVO) {
  return request({
    url: '/system/role',
    method: 'POST',
    data
  });
}

export function editRole(data: RoleVO) {
  return request({
    url: '/system/role',
    method: 'PUT',
    data
  });
}

export function delRole(id: number | number[]) {
  return request({
    url: `/system/role/${id}`,
    method: 'DELETE'
  });
}

export function roleDeptTree(id: number) {
  return request({
    url: `/system/role/deptTree/${id}`,
    method: 'GET'
  });
}

export function editDataScope(data: RoleVO) {
  return request({
    url: '/system/role/dataScope',
    method: 'put',
    data
  });
}
/**
 * 通过roleIds查询角色
 *
 * @param roleIds
 */
export const optionSelect = (roleIds: (number | string)[]) => {
  return request<Array<RoleVO>>({
    url: `/system/role/optionselect?roleIds=${roleIds}`,
    method: 'get'
  });
};
